package com.zhuiyun.pm.client.sc.service.servicelmpl;

import com.zhuiyun.pm.client.sc.entity.ClientTable;
import com.zhuiyun.pm.client.sc.entity.Intermediate;
import com.zhuiyun.pm.client.sc.mapper.TableMapper;
import com.zhuiyun.pm.client.sc.service.TableService;
import com.zhuiyun.pm.config.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName AddressServicelmpl
 * Description 发布service实现
 * Author Administrator
 * @Date 2023/3/14
 * Version 1.0
 **/
@Service
public class TableServiceImpl implements TableService {
    @Autowired
    TableMapper tableMapper;
    /**
     * 根据中间表id查询我的收藏
     * @author 温
     * @date 2023/3/15 15:38
     * @parameter [clientTable]
     * @return java.util.List<com.zhuiyun.pm.client.sc.entity.ClientTable>
     */
    @Override
    public List<ClientTable> TableList(Integer userId) {
        List<ClientTable> clientTables = tableMapper.TableList(userId);
        return clientTables;
    }

    @Override
    public void collect(Integer userId, Integer goodsid) {
        Intermediate intermediate = new Intermediate();
        intermediate.setUserId(userId);
        intermediate.setGoodId(goodsid);
        tableMapper.insertSelective(intermediate);
    }

    @Override
    public CommonResult selectCollect(Integer userId, Integer goodsid) {
        Intermediate intermediate = new Intermediate();
        intermediate.setUserId(userId);
        intermediate.setGoodId(goodsid);
        Intermediate select = tableMapper.selectOne(intermediate);
        if(select != null){
            return CommonResult.ok(true);
        }else{
            return CommonResult.ok(false);

        }
    }

    @Override
    public void delCollect(Integer userId, Integer goodsid) {
        Intermediate intermediate = new Intermediate();
        intermediate.setUserId(userId);
        intermediate.setGoodId(goodsid);
        tableMapper.delete(intermediate);

    }
}